package week05;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//@EnableAutoConfiguration // starter 自身不需要这个自动装载配置
@ConditionalOnClass(CampService.class)
@EnableConfigurationProperties(CampProperties.class)
public class CampAutoConfiguration {

    private CampProperties campProp;

    @Autowired
    public void setCampProp(CampProperties campProp) {
        this.campProp = campProp;
    }

    @Bean("camp")
    @ConditionalOnProperty(prefix = "camp", value = "started", havingValue = "true")
    CampService campService() {
        CampService service = new CampService();
        service.setDate(campProp.getDate());
        service.setWeek(campProp.getWeek());
        return service;
    }
}
